import { useSystemStore } from "@/store"
interface showOption{
	title: string,
	mask: boolean,
	success: (result:any)=>void,
	fail: (result:any)=>void,
	complete: (result:any)=>void
}
function showLoading(showOption:showOption){
	const systemStore = useSystemStore()
	const { isLoading, setLoading } = systemStore
	if(isLoading){
		uni.hideLoading()
	}
	uni.showLoading({
		title: showOption.title,
		mask: showOption.mask,
		success: showOption.success,
		fail: showOption.fail,
		complete: showOption.complete
	})
	setLoading(true)
}
function hideLoading(){
	const systemStore = useSystemStore()
	const { setLoading } = systemStore
	uni.hideLoading()
	setLoading(false)
}

export default {
	install(Vue,options){
		if(!uni || typeof uni !== "undefined"){
			uni.$tm = {showLoading,hideLoading}
		}
	}
}